const express = require("express");
const app = express();
const path = require("path")

//引入数据库连接文件
require("./db")


//引入外部路由
const addAdminRoute = require("./routes/addAdmin");
const adminListRoute = require("./routes/adminList");
const deleteAdminRoute = require("./routes/deleteAdmin")
const loginRoute = require("./routes/login")
const isLogin = require("./routes/isLogin")
const logout = require("./routes/logout")
const addAdv = require("./routes/addAdv")
const advList = require("./routes/advList")
//处理post请求体的中间件,会在req上添加一个body属性,值是请求体参数
app.use(express.urlencoded());
app.use(express.json());


//暴露静态资源文件夹
app.use("/upload", express.static(path.resolve(__dirname, "./upload")))


//使用路由
app.use(addAdminRoute)
app.use(adminListRoute)
app.use(deleteAdminRoute)
app.use(loginRoute)
app.use(isLogin)
app.use(logout)
app.use(addAdv)
app.use(advList)


app.listen("8000", () => {
  console.log("服务器启动成功 http://127.0.0.1:8000");
})